#include <iostream>
using std::cout;
using std::endl;

class Base{
public:
    Base(long x)
    : _base(x)
    {}

    virtual void display() const{
        cout << "Base::display()" << endl;
    }
    
    virtual void show() const{
        cout << "Base::show()" << endl;
    }

    void func1(){
        cout << "func1()" << endl;
    }
private:
    long _base;
};


class Derived
: public Base
{
public:
    Derived(long base,long derived)
    : Base(base)
    , _derived(derived)
    {}

    //override告诉编译器此处定义的虚函数是要对
    //基类的虚函数进行覆盖
    //覆盖要求函数的形式完全一致
    virtual void display() const override{
        cout << "Derived::display()" << endl;
    }

    virtual void func2(){
        cout << "func2()" << endl;
    }
private:
    long _derived;

};

void test0(){
    cout << sizeof(Base) << endl;
    cout << sizeof(Derived) << endl;

    Derived d1(4,9);
    Base * pbase = &d1;
    pbase->display();//动态多态
    pbase->show();//没有被覆盖，不满足动态多态条件
    //基类中没有定义func2，基类指针无法调用
    /* pbase->func2(); */

    d1.display();//这里理解为隐藏
}

int main(void){
    test0();
    return 0;
}
